package com.sxx.beautifulcity.database;

import android.util.Log;

import com.sxx.beautifulcity.entity.greendao.UserDaoEntity;
import com.sxx.beautifulcity.entity.greendao.UserDaoEntityDao;

import java.util.List;

import de.greenrobot.dao.query.QueryBuilder;
import de.greenrobot.dao.query.WhereCondition;

import static com.sxx.beautifulcity.entity.greendao.UserDaoEntityDao.*;

/**
 * Created by dllo on 15/11/3.
 */
public class UserHelper {
    private DaoSingleton instance = DaoSingleton.getInstance();
    private UserDaoEntityDao userDao;

    public UserHelper() {
        this.userDao = instance.getUserDao();
    }

    public void savaRegisterList(List<UserDaoEntity> entities) {
        Log.i("jjsfdj", entities + "");
        userDao.insertInTx(entities);
    }

    public void deleteUserList() {
        userDao.deleteAll();
    }

    public List<UserDaoEntity> queryUserAll() {
        return userDao.loadAll();
    }
    public List<UserDaoEntity> queryName(String name, String num){

        QueryBuilder qb = userDao.queryBuilder();
//        List<UserDaoEntity> list = qb.where((UserDaoEntityDao.Properties.UserName.eq(name)),
//                qb.or(UserDaoEntityDao.Properties.Zhanghao.eq(name))).list();
        List<UserDaoEntity> list = qb.whereOr(Properties.Zhanghao.eq(name),Properties.UserName.eq(num)).list();

//        QueryBuilder qb = userDao.queryBuilder();
//        QueryBuilder where = qb.where(Properties.UserName.eq(name),
//                qb.whereOr(Properties.Zhanghao.eq(name)));
//        List<UserDaoEntity> list = qb.list();

        return list;
    }
}
